layui.use(['layer', 'form'], function(){
    const layer = layui.layer
        ,$ = layui.$
        , form = layui.form;

    form.on('submit(login)', function(data){
        $.ajax({
            url:"/user/login",
            dataType: "json",
            data: data.field,
            type:"post",
            success:function(res){
                if (res.code==0){
                    window.sessionStorage.setItem("TOKEN",res.data.token);
                    window.sessionStorage.setItem("adminID",res.data.admin.adminID);
                    window.sessionStorage.setItem("adminName",res.data.admin.adminName);
                    window.location.href = "/home";
                }else{
                    layer.msg(res.msg,{icon:5});
                }
            },
            error:function(res){
                layer.msg("系统错误,请联系管理员!",{icon:5});
            }
        });
        return false;
    });

});